
from typing import Dict, List, Union
from commandsniffer.graph import CommandGraph
from commandsniffer.passes.command_pass import CommandPass
from commandsniffer.passes.graph_pass import GraphPass


def run_passes(graph: CommandGraph, passes: List[Union[GraphPass, CommandPass]]) -> None:
    for curr_pass in passes:
        if isinstance(curr_pass, GraphPass):
            curr_pass.run(graph)
        else:
            for command in list(graph.commands.values()):
                res = curr_pass.run(command)
                if res is not None:
                    res.take_action(graph)
